# Maintainer: taozuhong <taozuhong@gmail.com>

_realname=hiredis
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.0
pkgrel=1
pkgdesc="Minimalistic C client for Redis (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/redis/hiredis"
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openssl")
source=("https://github.com/redis/hiredis/archive/v${pkgver}.tar.gz")
sha256sums=('82ad632d31ee05da13b537c124f819eb88e18851d9cb0c30ae0552084811588c')

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  CFLAGS+=" -Wno-int-conversion" \
  MSYS2_ARG_CONV_EXCL=- \
    ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    ${_extra_config[@]} \
    -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX \
    -DENABLE_SSL=ON \
    -DDISABLE_TESTS=ON \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  # Remove NuGet package
  rm -rf "${pkgdir}"${MINGW_PREFIX}/build
}
